import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Day02 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        double weight = in.nextDouble();
        String type = in.next();
        int weightPic = 20;
        if (weight > 1) {
            weightPic += (int)Math.ceil(weight - 1);
        }

        System.out.println((int) (weightPic + (type.equals("y") ? 5 : 0)));
    }

    // 时间超时
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int len = in.nextInt();
        in.nextLine();
        int[] arr = toIntArr(in);

        System.out.println(getMinPic(arr, -1));
    }

    private static int getMinPic(int[] arr, int index) {
        if (index >= arr.length) {
            // 递归终止条件
            return 0;
        }
        int cur = 0;
        if (index >= 0) {
            cur = arr[index];
        }

        int first = getMinPic(arr, index + 1);// 第一个
        int second = getMinPic(arr, index + 2);// 第二个
        return Math.min(first, second) + cur;
    }

    private static int[] toIntArr(Scanner in) {
        String[] arr = in.nextLine().split(" ");
        int[] result = new int[arr.length];
        for (int i = 0; i < result.length; i++) {
            result[i] = Integer.parseInt(arr[i]);
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int len = in.nextInt();
        String str1 = in.next(), str2 = in.next();
        if (str1 == null || str2 == null) {
            System.out.println("-1");
            return;
        }
        in.nextLine();
        String[] arr = new String[len];
        for (int i = 0; i < len; i++) {
            arr[i] = in.nextLine();
        }

        // 获取它们的下标
        List<List<Integer>> indexs = getIndexs(str1, str2, arr);
        int min = getMinDistance(indexs.get(0), indexs.get(1));
    }

    private static int getMinDistance(List<Integer> list1, List<Integer> list2) {
        int min = Integer.MAX_VALUE;
        int index1 = 0, index2 = 0;
        while (index1 < list1.size() && index2 < list2.size()) {
            int num1 = list1.get(index1), num2 = list2.get(index2);
            int abs = Math.abs(num2 - num1);
//            if ()
        }

        return min;
    }

    private static List<List<Integer>> getIndexs(String str1, String str2, String[] arr) {
        List<List<Integer>> result = new ArrayList<>();
        result.add(new ArrayList<>());
        result.add(new ArrayList<>());
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].equals(str1)) {
                result.get(0).add(i);
            } else if (arr[i].equals(str2)) {
                result.get(1).add(i);
            }
        }

        return result;
    }
}
